import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/widgets/common/xindong_app_bar_icon_button.dart';

class XinDongAppBar extends AppBar {
  // 标题名称
  final String? name;

  // 标题栏
  final Widget? titleView;

  // 亮度（light - 背景亮色，状态栏文字黑色；dark - 背景暗色，状态栏文字白色）
  final Brightness brightness;

  // 类方法 - 获取着色
  static Color tintColor(Brightness brightness) {
    return brightness == Brightness.dark ? Colors.white : DZColors.titleColor;
  }

  // 构造函数
  XinDongAppBar(
    this.name, {
    Key? key,
    this.titleView, // 标题栏
    this.brightness = Brightness.light, //亮度（light - 背景亮色，状态栏文字黑色；dark - 背景暗色，状态栏文字白色）
    super.leading = const XinDongAppBarIconButton(), // 左侧视图
    super.leadingWidth = 44, // 左侧视图宽度
    super.elevation = 0.5, // 底部阴影大小，系统默认：4.0，App默认0.5
    super.automaticallyImplyLeading = true, //自动导入,显示返回按钮
    super.toolbarHeight = kAppBarHeight, // 标题间距
    super.titleSpacing = 0, // 标题间距
    super.actions, // 动作组件数组
        super.backgroundColor
  }) : super(
          key: key,
          centerTitle: true,
          systemOverlayStyle: SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            statusBarBrightness: brightness,
            statusBarIconBrightness: brightness == Brightness.dark ? Brightness.light : Brightness.dark,
            systemNavigationBarIconBrightness: brightness == Brightness.dark ? Brightness.light : Brightness.dark,
            systemNavigationBarColor: Colors.transparent,
          ),
          title: (titleView != null)
              ? titleView
              : (name == null || name.isEmpty)
                  ? null
                  : Text(
                      name,
                      style: TextStyle(color: tintColor(brightness), fontSize: kTitleFontSize, fontWeight: FontWeight.w500),
                    ),
        );
}
